import { reqAddcart, reqDetail } from "@/api";

const state = {
  detailList: {},
};
const mutations = {
  GETDETAIL(state, data) {
    state.detailList = data;
  },
};
const actions = {
  async getdetail({ state, commit, dispatch }, skuId) {
    let res = await reqDetail(skuId);
    if (res.code === 200) {
      commit("GETDETAIL", res.data);
    }
  },
  async goaddcartsuccess({ state, commit, dispatch }, { skuId, skuNum }) {
    let res = await reqAddcart({ skuId, skuNum });
    if (res.code == 200) {
      return "nihao";
    } else {
      return Promise.reject();
    }
  },
};
const getters = {
  categoryView(state) {
    return state.detailList.categoryView || {};
  },
  skuInfo(state) {
    return state.detailList.skuInfo || {};
  },
  spuSaleAttrList(state) {
    return state.detailList.spuSaleAttrList;
  },
};

export default { namespaced: true, state, mutations, actions, getters };
